#include <stdio.h>
#include <pthread.h>
#include <math.h>
#include <stdlib.h>

struct parameter{
    int *arr;
    int left;
    int right;
};

void* thread_sort(void* arg);

void swap(int *p1, int *p2){
	int tmp;
	tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}

void quickSort(int* arr, int left, int right){
    if(left >= right)
        return;
    int prev = left, cur = prev + 1;
    int pivot = arr[left];
    while(cur <= right){
        if(arr[cur] < pivot && ++prev != cur){
            swap(&arr[cur], &arr[prev]);
        }
        cur++;
    }
    swap(&arr[left], &arr[prev]);

    quickSort(arr, left, prev - 1);

    pthread_t th;
    int ret;

    struct parameter param;
    param.arr = arr;
    param.left = prev + 1;
    param.right = right;

    ret = pthread_create(&th, NULL, thread_sort, (void*)&param);
    if(ret != 0){
        printf("create thread error\n");
        exit(-1);
    }

    pthread_join(th, NULL);
}

void* thread_sort(void* arg){
    struct parameter *p = (struct parameter*)arg;
    quickSort(p->arr, p->left, p->right);
    return (void*)0;
}

int main(){
    int n;
    scanf("%d", &n);
    int arr[1005];
    for(int i = 0; i < n; i++){
        scanf("%d", &arr[i]);
    }
    
    quickSort(arr, 0, n - 1);

    for(int i = 0; i < n - 1; i++){
        printf("%d ", arr[i]);
    }
    printf("%d", arr[n - 1]);
	return 0;
}

/*
10
5 3 9 3 1 43 7 3 -4 -34
*/